package com.wanxi.demo;

import com.wanxi.tool.Tool;

import java.util.Arrays;

public class ReverseArr {
    public static void main(String[] args) {
        /**
         * 1.直接将最后一个和第一个交换位置，依此类推
         * 2.直接倒转
         */
        int[] arr = Tool.getIntArr(10);
        System.out.println(Arrays.toString(arr));
//        int[] arrB = reverseArr(arr);
        secondReverseArr(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void secondReverseArr(int[] arr) {
        int length = arr.length;
        for (int i = 0; i < arr.length / 2; i++) {
            int temp = arr[i];
            arr[i] = arr[length - 1];
            arr[length - 1] = temp;
            length--;
        }
    }

    private static int[] reverseArr(int[] arr) {
        int length = arr.length;
        int[] newArr = new int[length];
        for (int i = 0; i < arr.length; i++) {
            newArr[length - 1] = arr[i];
            length--;
        }
        return newArr;
    }
}
